<?php
include_once '../../mainfile.php';
include (XOOPS_ROOT_PATH . "/header.php"); 
?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="<?PHP echo XOOPS_URL . "modules/local_news/include/rss1html.xsl"; ?>"?>
<rss version="2.0">
  <channel>
    <title><?PHP echo $xoopsModuleConfig['stationLetters'] . '-FM Southeast News Podcasts'; ?></title>
    <link><?PHP echo XOOPS_URL; ?></link>
    <description><?PHP echo $xoopsModuleConfig['stationLetters'];?> - Public Broadcasting</description>
    <language>en-us</language>

    <copyright><?PHP echo "Copyright ".date("Y"). " " .$xoopsModuleConfig['stationLetters']."-FM"; ?></copyright>
    <pubDate><?PHP echo date("D, d M Y H:i:s"); ?></pubDate>

    <category>News Media - Radio Broadcasting</category>
    <generator><?PHP echo $xoopsModuleConfig['stationLetters']; ?> Website</generator>
    <ttl>30</ttl>
    
<?PHP

if ($xoopsModuleConfig['enableSyndication'] == 1) {
	$link = mysql_connect($xoopsModuleConfig['syndicationDB_Host'], $xoopsModuleConfig['syndicationDB_User'], $xoopsModuleConfig['syndicationDB_Passaword']) or ($error = mysql_error());
	$Query = "SELECT ID, tease, publish_date, headline, dateline, soundfile FROM CA_SE_News WHERE storyID NOT LIKE '" . strtoupper($xoopsModuleConfig['stationLetters']) . "%' AND soundfile != '' ORDER BY publish_date DESC LIMIT " . $xoopsModuleConfig['NISR'] . "";
	mysql_select_db($xoopsModuleConfig['syndicationDB']) or ($error = "Could not select database");
	$result = mysql_query($Query, $link) or ($error = "Query failed");

	function getFileSize($link){//http://krbd.org/modules/local_news/media/audio/03stevens.mp3
		$patterns = array("/http:\/\/kcaw.org/","/http:\/\/kfsk.org/","/http:\/\/krbd.org/","/http:\/\/kstk.org/");
		$replacements = array('/home/coastalaska/kcaw','/home/coastalaska/kfsk','/home/coastalaska/krbd','/home/coastalaska/kstk');
		return filesize(preg_replace($patterns, $replacements, $link));
	}

	if ($result) {
		$properties = array ();
		while ($myrow = mysql_fetch_array($result, MYSQL_ASSOC)) {
			echo "    <item>\n";
			echo "        <title>" . html_entity_decode($myrow['headline'], ENT_QUOTES, 'UTF-8') . "</title>\n";
			echo "        <link>" . XOOPS_URL . '/modules/local_news/index.php?op=sideBlock&amp;syndicated=true&amp;ID=' . $myrow['ID'] . "</link>\n";
			echo "        <description>Broadcast: " . date("m/d/Y", $myrow['publish_date']) . "</description>\n";
			echo "        <author>" . $xoopsModuleConfig['stationLetters'] . "-FM" . "</author>\n";
			echo "        <enclosure url=\"" . $myrow['soundfile'] . "\" length=\"" . getFileSize($myrow['soundfile']) . "\"  type=\"audio/mpeg\" />\n";
			echo "        <comments>" . XOOPS_URL . '/modules/local_news/index.php?op=sideBlock&amp;syndicated=true&amp;ID=' . $myrow['ID'] . "</comments>\n";
			echo "        <guid>" . XOOPS_URL . '/modules/local_news/index.php?op=sideBlock&amp;syndicated=true&amp;ID=' . $myrow['ID'] . "</guid>\n";
			echo "        <pubDate>" . date("D, d M Y H:i:s", $myrow['publish_date']) . "</pubDate>\n";
			echo "        <source url=\"" . XOOPS_URL . "/modules/local_news/index.php\">" . $xoopsModuleConfig['stationLetters'] . "&lt;FM" . "</source>\n";
			echo "    </item>";
		}
		mysql_free_result($result);
		mysql_close($link);
	}
}
?>    
  </channel>
</rss>